package com.db.NLP;

import java.util.ArrayList;
import java.util.Scanner;

import android.util.Log;

public class LanguageProcessing {
	
	public static String convertArrayListToStringSeparatedBySpace(ArrayList<String> x){
		String result = "";
		for(String s:x){
			result+=(x+" ");
		}
		return result;
	}
	
	public static String getKeywordsFromUserInput(String input){
		//ArrayList<String> result = new ArrayList<String>();
		String result = "";
		Scanner scanWord = new Scanner(input);
		while(scanWord.hasNext()){
			String word = scanWord.next();
			if(word.endsWith("?")){
				if(word.length()!=0){
					word = word.substring(0, word.length()-1);
				}
			}
			if(isKeyword(word)){
				Log.d("SCANNING WORD", word);
				result+=word+" ";
			}
		}
		while(result.endsWith(" ")){
			result = result.substring(0, result.length()-1);
		}
		return result;
	}
	
	public static boolean isKeyword(String x){
		if(isCategory(x)){
			return false;
		}
		if(isExtraWord(x)){
			return false;
		}

		if(isLinkingVerb(x)){
			return false;
		}
		return true;
	}
	
	private static boolean isLinkingVerb(String x) {
		return x.equalsIgnoreCase("is") || x.equalsIgnoreCase("am") ||
			   x.equalsIgnoreCase("are") || x.equalsIgnoreCase("was")||
			   x.equalsIgnoreCase("were");
	}

	private static boolean isExtraWord(String x) {
		return x.equalsIgnoreCase("the") || x.equalsIgnoreCase("of");
	}

	public static boolean isCategory(String x){
		return x.equalsIgnoreCase("Who") || x.equalsIgnoreCase("What") ||
			   x.equalsIgnoreCase("Where") || x.equalsIgnoreCase("When") ;
	}
	
	
}
